package com.zhijian.medical.util;

import java.util.List;

/**
 * @Description 分页查询结果
 * @Author chengqing
 * @Date 2019年4月4日 下午2:17:37
 * @Version 1.0.1
 */
public class Page<T> {
    /**
     * 是否开启分页,默认false,当前端未传入pageNum与pageSize时,即认为不开启分页
     */
    private boolean isPage = false;
    /**
     * 总数据行数
     */
    private int totalCount;
    /**
     * 总页数
     */
    private int pageCount;
    /**
     * 当前页码,默认1
     */
    private int pageNum = 1;
    /**
     * 起始查询行,默认0
     */
    private int startIndex = 0;
    /**
     * 每页数据大小,默认10
     */
    private int pageSize = 10;
    /**
     * 当前页数据明细
     */
    private List<T> data;

    public Page() {
        super();
    }

    /**
     * @param isPage     是否开启分页
     * @param totalCount 总数据行数
     * @param pageNum    页码
     * @param pageSize   每页数据大小
     */
    public Page(boolean isPage, int totalCount, int pageNum, int pageSize) {
        super();
        this.isPage = isPage;
        if (this.isPage) {
            this.totalCount = totalCount;
            this.pageNum = pageNum;
            this.pageSize = pageSize;
            this.startIndex = this.pageNum <= 0 ? 0 : ((this.pageNum - 1) * this.pageSize);
        }
    }

    public boolean isPage() {
        return isPage;
    }

    public void setPage(boolean isPage) {
        this.isPage = isPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getPageCount() {
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public int getStartIndex() {
        return startIndex;
    }

    public void setStartIndex(int startIndex) {
        this.startIndex = startIndex;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
        //计算分页信息
        if (isPage) {
            this.pageCount = (this.totalCount % this.pageSize) > 0 ? ((this.totalCount / this.pageSize) + 1)
                    : this.totalCount / this.pageSize;
            //this.pageNum += 1;
        }
    }
}
